home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / DistUpgrade / DistUpgradeConfigParser.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  2.9 KB  |  77 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from ConfigParser import ConfigParser, NoOptionError, NoSectionError
  5. import subprocess
  6. import os.path as os
  7. import logging
  8. import glob
  9. CONFIG_OVERRIDE_DIR = '/etc/update-manager/release-upgrades.d'
  10.  
  11. class DistUpgradeConfig(ConfigParser):
  12.     
  13.     def __init__(self, datadir, name = 'DistUpgrade.cfg'):
  14.         ConfigParser.__init__(self)
  15.         from_release = subprocess.Popen([
  16.             'lsb_release',
  17.             '-c',
  18.             '-s'], stdout = subprocess.PIPE).communicate()[0].strip()
  19.         self.datadir = datadir
  20.         if os.path.exists(name + '.' + from_release):
  21.             name = name + '.' + from_release
  22.         
  23.         maincfg = os.path.join(datadir, name)
  24.         override_dir = CONFIG_OVERRIDE_DIR
  25.         self.config_files = [
  26.             maincfg]
  27.         for cfg in glob.glob(override_dir + '/*.cfg'):
  28.             self.config_files.append(cfg)
  29.         
  30.         self.read(self.config_files)
  31.  
  32.     
  33.     def getWithDefault(self, section, option, default):
  34.         
  35.         try:
  36.             return self.get(section, option, raw = True)
  37.         except (NoSectionError, NoOptionError):
  38.             e = None
  39.             return default
  40.  
  41.  
  42.     
  43.     def getlist(self, section, option):
  44.         
  45.         try:
  46.             tmp = self.get(section, option)
  47.         except (NoSectionError, NoOptionError):
  48.             e = None
  49.             return []
  50.  
  51.         items = [ x.strip() for x in tmp.split(',') ]
  52.         return items
  53.  
  54.     
  55.     def getListFromFile(self, section, option):
  56.         
  57.         try:
  58.             filename = self.get(section, option)
  59.         except NoOptionError:
  60.             return []
  61.  
  62.         p = os.path.join(self.datadir, filename)
  63.         if not os.path.exists(p):
  64.             logging.error("getListFromFile: no '%s' found" % p)
  65.         
  66.         items = [ x.strip() for x in open(p) ]
  67.         return filter((lambda s: if not s.startswith('#'):
  68. passnot (s == '')), items)
  69.  
  70.  
  71. if __name__ == '__main__':
  72.     c = DistUpgradeConfig()
  73.     print c.getlist('Distro', 'MetaPkgs')
  74.     print c.getlist('Distro', 'ForcedPurges')
  75.     print c.getListFromFile('Sources', 'ValidMirrors')
  76.  
  77.